import java.lang.reflect.InvocationHandler;
import java.lang.reflect.Method;
import java.lang.reflect.Proxy;
import java.util.Properties;

/**
 * @author ml
 * @create 2017-08-22--16:53
 */
public class HelloDynamicProxy implements InvocationHandler {
    Object subject;
    public HelloDynamicProxy(Object object){
        this.subject=object;
    }
    @Override
    public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
        System.out.println("before invoke "+method.getName());

        method.invoke(subject,args);

        System.out.println("after invoke "+method.getName());
        return null;
    }

    public static void main(String[] args) {

        Hello hello=new Hello();
        InvocationHandler helloproxy=new HelloDynamicProxy(hello);
        HelloInterface helloInterface= (HelloInterface) Proxy.newProxyInstance(helloproxy.getClass().getClassLoader(),hello.getClass().getInterfaces(),helloproxy);
        helloInterface.say();
    }
}
